package com.javaclimb.music.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.javaclimb.music.enums.ResponseEnum;
import lombok.Data;

/**
 * @author 最酷的桃儿wjc
 * * @date 2022/5/16
 */
@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResponseVo<T> {

    private Integer code;

    private String msg;

    private T data;

    public ResponseVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseVo(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVo(T data) {
        this.data = data;
    }

    public static <T> ResponseVo<T> success(ResponseEnum responseEnum){
        return new ResponseVo<>(responseEnum.getCode(),responseEnum.getMsg());
    }

    public static <T> ResponseVo<T> error(ResponseEnum responseEnum){
        return new ResponseVo<>(responseEnum.getCode(),responseEnum.getMsg());
    }

    public static <T> ResponseVo<T> successData(ResponseEnum responseEnum,T data){
        return new ResponseVo<>(responseEnum.getCode(),responseEnum.getMsg(),data);
    }

    public static <T> ResponseVo<T> getData(T data){
        return new ResponseVo<>(data);
    }





}
